// Metgine/Core/Game.h
//
// Copyright 2011 Phillip Stephens
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// Linking this library statically or dynamically with other modules is
// making a combined work based on this library.  Thus, the terms and
// conditions of the GNU General Public License cover the whole
// combination.

#ifndef GAME_H
#define GAME_H

#include <Metgine/Core/World.h>
#include <Metgine/Core/Camera.h>
#include <Metgine/Core/Vector2.h>
#include <Metgine/Core/Singleton.h>
#include <Metgine/Core/Log.h>
#include <Metgine/UI/UIManager.h>
#include <Metgine/Graphics/FXManager.h>

using namespace Metgine::Core;
using namespace Metgine::UI;
using namespace Metgine::Graphics;

namespace Metgine
{
namespace Core
{

namespace GameState
{
    enum GameState
    {

        None,                    // Initial state when the app is loaded
        MainMenu,                // On the main menu
        Game,                    // In the game world

    };
}

class Game
{

public:

    // Update the game
    void Update(float elapsedTime);

    // Render the game
    void Render();

    // Gets a pointer to the world
    static World* GetWorld();

    FXManager* GetFXManager() const;
    // Gets a pointer to the ui manager
    UIManager* GetUIManager() const;

    // Loads resources for a given game state
    virtual void LoadResourcesForState(GameState::GameState gameState)=0;

    // Changes the game state
    virtual void ChangeGameState(GameState::GameState gameState)=0;

    // Gets the current game state
    GameState::GameState GetGameState() const;

    // Creates the main menu screen
    virtual void CreateMainMenu()=0;

    // Creates the world
    virtual void CreateWorld()=0;

    // Sets up the world, called after CreateWorld
    virtual void SetupWorld()=0;

    // Gets the game camera
    Camera* GetCamera() const;

    // Shows a loading screen
    virtual void SetLoading(bool state)=0;

    // Fired when resources for a state have completed loading
    virtual void ResourcesLoaded()=0;

    // Writes a message to the debug log
    void Log(LogType::LogType type, const char* format, ...);


/*    b2World* GetPhysWorld() const;*/
protected:
    Game();
    ~Game();
    static World*                     m_world;                // Pointer to the game world

    UIManager*                        m_uiManager;            // Pointer to the UI manager
    FXManager*                        m_fxManager;            // Pointer to FXManager instance

    Camera*                           m_camera;                // Camera instance

    GameState::GameState              m_state;                // Current game state

    bool                              m_noAction;            // Set to true if nothing moved on the last update

    Vector2i                          m_cursorPosition;        // Current position of the mouse cursor in screen space

    bool                              m_loading;            // Are we waiting for resources to load?
};

}; // Core
}; // Metgine

#endif // GAME_H
